package com.quanyue.music.support;

import com.quanyue.auto.miniapp.domain.WechatMiniAppConfig;
import com.quanyue.auto.miniapp.service.MiniAppService;
import com.quanyue.auto.pay.PayType;
import com.quanyue.auto.pay.WechatPayConfig;
import com.quanyue.auto.util.AssertUtils;
import com.quanyue.music.domain.entity.Domain;
import com.quanyue.music.system.service.DomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WechatPayConfigImpl implements WechatPayConfig {

    @Autowired
    private DomainService domainService;
    @Autowired
    private MiniAppService miniAppService;

    @Override
    public String appId(Integer merchantNo) {
        WechatMiniAppConfig appConfig = miniAppService.findByMerchantNo(merchantNo);
        AssertUtils.notNull(appConfig, "小程序配置不存在");
        return appConfig.getAppId();
    }

    @Override
    public String domainUrl(PayType type, Integer merchantNo) {
        Domain domain = domainService.findByMerchantNo(merchantNo);
        AssertUtils.notNull(domain, "域名配置不存在");
        if (type == PayType.PAY) {
            return domain.getDomain() + "/wechat/pay/confirm";
        } else {
            return domain.getDomain() + "/wechat/refund/confirm";
        }
    }
}
